import {
  defineConfig,
  transformerDirectives,
  transformerVariantGroup,
  presetIcons
} from 'unocss'

import { presetUni } from '@uni-helper/unocss-preset-uni'

export default defineConfig({
  presets: [
    presetUni({
      attributify: {
        prefixedOnly: true,
      },
    }),
    presetIcons({
      cdn: 'https://esm.sh/',
      extraProperties: {
        display: 'inline-block',
        'vertical-align': 'middle',
      },
    }),
  ],
  rules: [
    [
      /^flex-(\d+)$/,
      ([, d]) => ({
        flex: `${d} ${d} 0`,
      }),
    ],
    [
      /^icon-(\d+)/,
      ([, d]) => ({
        width: `${d}rpx`,
        height: `${d}rpx`,
      }),
    ],
    [
      /^flex-center/,
      () => ({
        display: 'flex',
        'align-items': 'center',
        'justify-content': 'center'
      })
    ]
  ],

  transformers: [
    transformerDirectives(),
    transformerVariantGroup(),
  ],
})